/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package databook.util;

import prefuse.visual.VisualItem;
import prefuse.action.assignment.ColorAction;
import prefuse.util.ColorLib;
import prefuse.data.Edge;

import databook.WeightTree;
import databook.DatabookViz;
import databook.controller.Props;

/**
 *
 * @author zach
 */
public class MyColorAction extends ColorAction {
    private SimpleTransformFunction transform;
    private DatabookViz viz;

    public MyColorAction(String group, String field, SimpleTransformFunction stf, DatabookViz viz) {
        super(group,field);
        this.transform = stf;
        this.viz = viz;
    }
    
    public MyColorAction(String group, String field, int color, DatabookViz viz) {
        super(group,field,color);
        this.viz = viz;
    }
    
    public int getColor(VisualItem item) { 
        int c;
        if (transform == null)
            c = super.getColor(item);
        else {
            double weight = ((WeightTree)item.get(DatabookViz.TREE_COLUMN)).getSize();
            c = transform.getColor(weight);
        }
        if (Props.get(Props.SELECTED_ITEM) != null) {
            if (item.getString("SELECTED")!= null) {
                if (m_colorField.equals(VisualItem.TEXTCOLOR)) {
                    return Props.getColor(Props.DEFAULT_NODE_TEXT);
                } else {
                    return Props.getColor(item.getString("SELECTED"));
                }
            } else {
                return ColorLib.makeTransparent(c, .45);
            }
        }
        return c;
    }
}
